import instance from '@/utils/request'
import { IAxiosRes, TAtilcle } from '.'

/**
 * 获取联想建议（自动补全）
   基本信息
   Path： /v1_0/suggestion
   Method： GET
 */
export declare type TSuggestion = {
  options: string[] | null[]
}
export const getSuggestion = (q: string): IAxiosRes<TSuggestion> => {
  return instance({
    url: `/suggestion?q=${q}`
  })
}

/**
 * 获取搜索结果
   基本信息
   Path： /v1_0/search
   Method： GET
 */
export declare type TSearch = {
  page: number
  per_page: number
  results: TAtilcle[]
  total_count: number
}
export const getSearch = (
  q: string,
  page?: number,
  per_page?: number
): IAxiosRes<TSearch> => {
  let url: string = `/search?q=${q}`
  if (page !== undefined) {
    url += `&page=${page}`
  }
  if (per_page !== undefined) {
    url += `&per_page=${per_page}`
  }
  return instance({
    url: url
  })
}
